package org.wu.mp.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.wu.mp.domain.Employee;
import org.wu.mp.service.IEmployeeService;
import org.wu.mp.utils.JsonResult;

import java.util.List;

@RestController
@RequestMapping("employees")
public class EmployeeController {

    @Autowired
//    private EmployeeServiceImpl employeeService;
    private IEmployeeService employeeService;

    @GetMapping("/list")
    public List<Employee> list(){
        return employeeService.list();
    }

    @PostMapping("/add")
    public JsonResult add(Employee employee){
        employeeService.save(employee);
        return JsonResult.success();
    }

    @GetMapping("/detail")
    public Employee detail(Long id){
        return employeeService.getById(id);
    }

    @PostMapping("/edit")
    public JsonResult edit(Employee employee){
        employeeService.updateById(employee);
        return JsonResult.success();
    }

}
